<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta charset="utf-8"/>

    <meta name="keywords" content="{$Think.CONFIG.keywords}"/>
    <meta name="description" content="{$Think.CONFIG.description}"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

    {include file="public/head" /}

</head>
<body>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <div class="main-container-inner">
        <a class="menu-toggler" id="menu-toggler" href="#">
            <span class="menu-text"></span>
        </a>

        {include file="public/nav"/}

        {include file="public/menu"/}

        <div class="main-content">
            {include file="public/breadcrumb"/}

            <div class="page-content">
                <div class="row">
                    <div class="cf">
                        <a class="btn btn-info" href="{:Url('add')}">新增</a>
                    </div>
                    <div class="space-4"></div>
                    <table class="table table-bordered table-striped">
                        <tr>
                            <td align="center">车牌号</td>
                            <td align="center">车型</td>
                            <td align="center">车架号</td>
                            <td align="center">会员等级</td>
                            <td align="center">会员余额</td>
                            <td align="center">已消费金额</td>
                            <td align="center">操作</td>
                        </tr>
                        {volist name='list' id='car'}
                        <tr>
                            <td align="center">{$car.car_num}</td>
                            <td align="center">{$car.car_type}</td>
                            <td align="center">{$car.vin}</td>
                            <td align="center">{$car.vip}</td>
                            <td align="center" id="ml{$car.car_num}">{$car.moneyleft}</td>
                            <td align="center">{$car.moneyconsumption}</td>
                            <td align="center">
                                <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
                                    <button title="会员充值" class="btn btn-xs btn-success"
                                            onclick="car.inm('{$car.car_num}');">
                                        <i class="fa fa-sign-in bigger-120"></i>
                                    </button>
                                    <button title="修改" class="btn btn-xs btn-info"
                                            onclick="car.edit('{:url(\'add\',[\'car_num\'=>$car.car_num])}');">
                                        <i class="fa fa-edit bigger-120"></i>
                                    </button>
                                    <button title="删除" class="btn btn-xs btn-danger"
                                            onclick="car.del('{$car.car_num}');">
                                        <i class="fa fa-trash bigger-120"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                    </table>
                    <!--充值模态框-->
                    <div id="modal-fmRecharge" class="modal" tabindex="-1">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h4 class="blue bigger">
                                        充值 (<span style="color:red;" id="inMoneyCarNum"></span>)
                                    </h4>
                                </div>
                                <div class="modal-body overflow-visible">
                                    <!--充值金额表单-->
                                    <form class="form-horizontal" id="fmRecharge" method="post">
                                        <input type="hidden" name="car_num" value="">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label no-padding-right">充值金额</label>
                                            <div class="col-sm-9">
                                                <input type="number" name="charge" class="col-xs-10 col-sm-5" value="">
                                                <span class="help-inline col-xs-12 col-sm-7">
                                <span class="middle"></span>
                              </span>
                                            </div>
                                        </div>
                                    </form>
                                </div>

                                <div class="modal-footer">
                                    <button class="btn btn-sm" data-dismiss="modal">
                                        <i class="icon-remove"></i>
                                        取消
                                    </button>
                                    <button class="btn btn-sm btn-primary" onclick="car.doCharge(this);"
                                            data-loading-text="保存中...">
                                        <i class="icon-ok"></i>
                                        保存
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div><!-- /.main-content -->

    </div><!-- /.main-container-inner -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="fa fa-angle-double-up fa-only bigger-110"></i>
    </a>
</div>
</body>
{include file="public/footerjs"/}
<script src="__ADMIN__/ace/js/bootbox.min.js"></script>

<script>
    (function () {
        car = {
            edit: function (url) {
                location.href = url;
            },
            del: function (car_num) {
                bootbox.confirm("确定要删除该条数据？", function (result) {
                    if (result)
                        $.post("{:url('del')}", {car_num: car_num}, function (data) {
                            if (data > 0) {
                                bootbox.alert("删除成功");
                                setTimeout(function () {
                                    location.reload();
                                }, 1000)
                            } else {
                                bootbox.alert("删除失败");
                            }
                        })

                });

            },
            inm: function (car_num) {
                $("#inMoneyCarNum").text(car_num);
                $('#modal-fmRecharge').modal('show');
                $('#fmRecharge input[name=car_num]').val(car_num);
            },
            doCharge: function (obj) {
                var param = ittaoli.serializeObject($('#fmRecharge'));
                if (param.car_num == '') {
                    bootbox.alert('无车牌，请先去完善车辆信息！');
                    return;
                }
                if (param.charge == '') {
                    bootbox.alert('请正确输入充值金额！');
                    return;
                }
                if (!ittaoli.regs.int.test(param.charge)) {
                    bootbox.alert('充值金额请输入整数！');
                    return;
                }
                console.log(JSON.stringify(param));

                $(obj).button('loading');
                $.post('{:url("work/doRecharge")}', {param: JSON.stringify(param)}, function (data) {
                    if (data > 0) {
                        $('#modal-fmRecharge').modal('hide');
                        $(obj).button('reset');
                        $('#fmRecharge')[0].reset();
                        var money = $('#ml' + param.car_num).text();
                        $('#ml' + param.car_num).text(parseFloat(money) + parseFloat(param.charge));
                        // $('#fmMember input[name=car_moneyleft]').val(parseFloat(money) + parseFloat(param.charge));
                        // bootbox.alert("充值成功！");
                        // setTimeout(function () {
                        //     location.reload();
                        // }, 1000)
                    } else {
                        bootbox.alert('充值失败！');
                    }
                })
            }
        }
    }());
</script>

{include file="public/foot" /}
